package com.Mobile.Action;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import sun.misc.BASE64Decoder;
import transformFactory.OperateImage;

import com.Action.ClubAction;
import com.Entity.Club;
import com.Entity.DoctorInfo;
import com.Entity.Favoritetopic;
import com.Entity.Topic;
import com.Entity.Topicclassify;
import com.Entity.Topiccomment;
import com.Entity.Userdata;
import com.Entity.Users;
import com.Service.ClubService;
import com.Service.DoctorInfoService;
import com.Service.FavoriteTopicService;
import com.Service.TopicClassifyService;
import com.Service.TopicCommentService;
import com.Service.TopicService;
import com.Service.UserdataService;
import com.Service.UsersService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.util.Base64;
import com.sun.org.apache.xerces.internal.impl.xpath.regex.ParseException;

public class MobileClubAction implements ServletResponseAware {

	
	private static final Logger logger = Logger.getLogger(ClubAction.class);
	private static final String ERRO="erro";
	private int flag=0;
	private HttpServletResponse response;//response对象
	
	

	@Autowired
	private ClubService clubService;
	@Autowired
	private TopicService topicService;
	@Autowired
	private TopicClassifyService topicClassifyService;
	@Autowired
	private TopicCommentService topicCommentService;
	@Autowired
	private UsersService usersservice;
	@Autowired
	private UserdataService userdataservice;
	@Autowired
	private FavoriteTopicService favoriteTopicservice;
	@Autowired
	private DoctorInfoService doctorInfoService;
	
	Club club=new Club();
	Topic topic=new Topic();
	Users commentuser=new Users();
	Userdata userdata=new Userdata();
	Userdata commentuserdata=new Userdata();
	List<Topicclassify> topicClassifyList=new ArrayList<Topicclassify>();
	List<Topic> topiclist=new ArrayList<Topic>();
	List<Topiccomment> topiccommentlist=new ArrayList<Topiccomment>();
	List<Users> commentuserlist=new ArrayList<Users>();
	List<Userdata> commentuserdatalist=new ArrayList<Userdata>();
	
	private File upload;  //文件
	private String uploadContentType;  //文件类型
	private String uploadFileName;   //文件名
	
	//circle topics
	public void selectClub() throws Exception{
		String clubid= ServletActionContext.getRequest().getParameter("clubid");
		String pageNum =  ServletActionContext.getRequest().getParameter("pageNum");
		String pageSize =  ServletActionContext.getRequest().getParameter("pageSize");
	    HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("application/json;charset=utf-8");
		PrintWriter out = response.getWriter();
		
		JSONObject returnjson=new JSONObject();
		JSONArray jsonarray=new JSONArray();
		int intclubid=Integer.parseInt(clubid);
		int intpageNum = Integer.parseInt(pageNum);
		int intpageSize = Integer.parseInt(pageSize);
		if(clubid!=null&&!clubid.equals("")){		
			topiclist=topicService.getTopicListByClubId(intclubid,0, intpageNum, intpageSize);
			System.out.println(topiclist);
            if(topiclist!=null){
            	
            	List<Map<String, Object>> topics=new ArrayList<Map<String, Object>>();
            	
            	for(Topic temTopic:topiclist){
            		int userId = temTopic.getTopicAuthorId();
            		Users user = usersservice.findByUserID(userId);
            		
            		Map<String, Object> params = new HashMap<String, Object>();
    				params.put("topic", temTopic);
    				params.put("userNickName",user.getNickName() );
    				params.put("userName",user.getUserName() );
    				topics.add(params);
				}
            	JSONArray jsonbean=JSONArray.fromObject(topics);
				flag=1;
				returnjson.put("flag",flag);
		
				returnjson.put("info", jsonbean);				
			}
			else{
				returnjson.put("flag", flag);
			}
		}
		else{
			returnjson.put("flag", flag);
		}
		out.println(returnjson.toString());
		out.flush();
		out.close();
	}
	
	//same age categories
	public void periodcategories() throws Exception{
		
		 HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("application/json;charset=utf-8");
		 PrintWriter out = response.getWriter();
		 
		JSONObject returnjson=new JSONObject();
		
		List<Club> clubcategories = clubService.findSameYearClub();
		System.out.println(clubcategories);
        if(clubcategories!=null){
        	
        	List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        	
        	for(Club club:clubcategories){
        	
        		Map<String, Object> params = new HashMap<String, Object>();
        		params.put("period", club);
        		int periodClubid = club.getClubCategoryId();
        		params.put("topicCount",topicService.countTopicByClubId(periodClubid));
        		list.add(params);
        	}
        	
        	JSONArray jsonbean=JSONArray.fromObject(list);
			flag=1;
			returnjson.put("flag",flag);
			returnjson.put("info", jsonbean);				
		}
		else{
			returnjson.put("flag", flag);
		}
       
        out.println(returnjson.toString());
		out.flush();
		out.close();
		
	}
	//getclassifylist
	public void getclassifylist() throws Exception{
		
		 HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("application/json;charset=utf-8");
		 PrintWriter out = response.getWriter();
		 
		JSONObject returnjson=new JSONObject();
		
		List<Topicclassify> topiccategories = topicClassifyService.find();
		System.out.println(topiccategories);
       if(topiccategories!=null){
       	
       	JSONArray jsonbean=JSONArray.fromObject(topiccategories);
			flag=1;
			returnjson.put("flag",flag);
			returnjson.put("info", jsonbean);				
		}
		else{
			returnjson.put("flag", flag);
		}
      
       out.println(returnjson.toString());
		out.flush();
		out.close();
		
	}
	
	
	//topic comments
	public void topicComment() throws Exception{
		
		String topicid= ServletActionContext.getRequest().getParameter("topicid");
		String pageNum =  ServletActionContext.getRequest().getParameter("pageNum");
		String pageSize =  ServletActionContext.getRequest().getParameter("pageSize");
		
		 HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("application/json;charset=utf-8");
		PrintWriter out = response.getWriter();
		JSONObject returnjson=new JSONObject();
		
		
		if(topicid != null){
		
		int inttopicid=Integer.parseInt(topicid);
		int intpageNum = Integer.parseInt(pageNum);
		int intpageSize = Integer.parseInt(pageSize);
		
		List<Topiccomment> commentlist = topicCommentService.getTopicCommentByTopicId(inttopicid, intpageNum, intpageSize); 
		if(commentlist!=null){
        
				List<Map<String, Object>> topicComments = new ArrayList<Map<String, Object>>();
				
				if(commentlist.size()>0){
					for(int i=0;i<commentlist.size();i++){
						Topiccomment _topicComment= commentlist.get(i);
						Map<String, Object> params = new HashMap<String, Object>();
						params.put("comment", _topicComment);
						
						if(_topicComment != null){
						
						int tempuserId = _topicComment.getCommentAuthorId();
		        		Users user = usersservice.findByUserID(tempuserId);
		        		if(user != null){
		        		params.put("userNickName",user.getNickName() );
						params.put("userName",user.getUserName() );
		        		}
		        		else{
		        			params.put("userNickName","somebody");
							params.put("userName","somebody");
		        		}
						topicComments.add(params);
						}
					}
				}
			
			JSONArray jsonbean=JSONArray.fromObject(topicComments);
			flag=1;
			returnjson.put("flag",flag);
			returnjson.put("info", jsonbean);				
		}
		else{
			returnjson.put("flag", flag);
		}
		}
		else{
			returnjson.put("flag", flag);
		}
        out.println(returnjson.toString());
		out.flush();
		out.close();
	}
	
	//topic favor
	public void topicFavor() throws Exception{
		String topicId= ServletActionContext.getRequest().getParameter("topicId");
		String userId =  ServletActionContext.getRequest().getParameter("userId");
		
		long inttopicid=Integer.parseInt(topicId);
		int intuserId = Integer.parseInt(userId);
	
		 HttpServletResponse response = ServletActionContext.getResponse();
					response.setContentType("application/json;charset=utf-8");
					PrintWriter out = response.getWriter();
					JSONObject returnjson=new JSONObject();
	    if(topicId != null){
		//time
		Favoritetopic favoritetopic=new Favoritetopic();
				Timestamp nowtime = new Timestamp(System.currentTimeMillis());
				favoritetopic.setFavoriteTime(nowtime);
				favoritetopic.setTopicId(inttopicid);
				favoritetopic.setUserId(intuserId);
				favoriteTopicservice.save(favoritetopic);
				//更新帖子的收藏数
				topic=this.topicService.getById(inttopicid);
				topic.setFavoriteNumber(topic.getFavoriteNumber()+1);
				this.topicService.update(topic);
				
					flag=1;
					returnjson.put("flag",flag);
	    }
	    else{
	    	flag=0;
			returnjson.put("flag",flag);
	    }
					 out.println(returnjson.toString());
						out.flush();
						out.close();
	}
	
	//cancle favor
	public void cancleFovor() throws Exception{
		String favoritetopicId= ServletActionContext.getRequest().getParameter("favoriteTopicId");
	
		long intfavoritetopicid=Integer.parseInt(favoritetopicId);
	
	
		 HttpServletResponse response = ServletActionContext.getResponse();
					response.setContentType("application/json;charset=utf-8");
					PrintWriter out = response.getWriter();
					JSONObject returnjson=new JSONObject();
	    if(favoritetopicId != null){
	    	Favoritetopic favoritetopic=favoriteTopicservice.getById(intfavoritetopicid);
			this.favoriteTopicservice.delete(favoritetopic);
	    	//更新帖子的收藏数
			topic=this.topicService.getById(favoritetopic.getTopicId());
			topic.setFavoriteNumber(topic.getFavoriteNumber()-1);
			this.topicService.update(topic);
				
					flag=1;
					returnjson.put("flag",flag);
	    }
	    else{
	    	flag=0;
			returnjson.put("flag",flag);
	    }
					 out.println(returnjson.toString());
						out.flush();
						out.close();
		
	}
	
	//favorlist
	public void listFavorTopics() throws Exception{
		String userId= ServletActionContext.getRequest().getParameter("userId");
		String pageNum =  ServletActionContext.getRequest().getParameter("pageNum");
		String pageSize =  ServletActionContext.getRequest().getParameter("pageSize");
		
		 HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("application/json;charset=utf-8");
		PrintWriter out = response.getWriter();
		JSONObject returnjson=new JSONObject();
		
		
		if(userId != null){
		
		int intuserId=Integer.parseInt(userId);
		int intpageNum = Integer.parseInt(pageNum);
		int intpageSize = Integer.parseInt(pageSize);
		List<Favoritetopic> favoritelist = favoriteTopicservice.getFavoriteTopicList(intuserId, intpageNum, intpageSize);
		if(favoritelist!=null){
        	
			List<Map<String, Object>> favoriteTopics = new ArrayList<Map<String, Object>>();
			
			if(favoritelist.size()>0){
				for(int i=0;i<favoritelist.size();i++){
					this.topic=this.topicService.getById(favoritelist.get(i).getTopicId());
					Map<String, Object> params = new HashMap<String, Object>();
					params.put("topic", topic);
					
					if(topic != null){
					
					int tempuserId = topic.getTopicAuthorId();
	        		Users user = usersservice.findByUserID(tempuserId);
	        		params.put("userNickName",user.getNickName() );
					params.put("userName",user.getUserName() );
					
					favoriteTopics.add(params);
					}
				}
			}
			
        	JSONArray jsonbean=JSONArray.fromObject(favoriteTopics);
			flag=1;
			returnjson.put("flag",flag);
	
			returnjson.put("info", jsonbean);		
						
		}
		else{
			returnjson.put("flag", flag);
		}
		}
		else{
			returnjson.put("flag", flag);
		}
        out.println(returnjson.toString());
		out.flush();
		out.close();
	
		
	}
	
	//send topic
	//@RequestMapping(value="/circle_sendtopic",method=RequestMethod.POST)
	//@ResponseBody
	public void sendtopic() throws Exception{
		
		 PrintWriter out = response.getWriter();
		
		StringBuffer jb = new StringBuffer();
		  String line = null;
		  try {
		    BufferedReader reader = ServletActionContext.getRequest().getReader();
		    while ((line = reader.readLine()) != null)
		      jb.append(line);
		  } catch (Exception e) { /*report an error*/ }

		  HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("application/json;charset=utf-8");
		  
		  try {
		    JSONObject jsonObject = JSONObject.fromObject(jb.toString());
		    Integer clubId = jsonObject.getInt("clubId");
		    Integer topicClassifyId = jsonObject.getInt("topicClassifyId");
			String  topicTitle = jsonObject.getString("topicTitle");
			String  topicContent = jsonObject.getString("topicContent");
			Integer topicAuthorId = jsonObject.getInt("topicAuthorId");
			Integer doctorid=jsonObject.getInt("doctorid");
			
			if(jsonObject.containsKey("topicImageUrl") && jsonObject.getString("topicImageUrl") != null){
				String  topicImageUrl = jsonObject.getString("topicImageUrl");
				topic.setTopicImageUrl(topicImageUrl);
			}
			
			topic.setClubCategoryId(clubId);
			topic.setTopicClassifyId(topicClassifyId);
			topic.setTopicTitle(topicTitle);
			topic.setTopicContent(topicContent);
			topic.setTopicAuthorId(topicAuthorId);
			topic.setDoctorId(doctorid);
			
			Timestamp nowtime = new Timestamp(System.currentTimeMillis());
			topic.setTopicCreatedTime(nowtime);
			topic.setCommentNumber(0);
			topic.setIsClassical(0);
			topic.setScanNumber(0);
			topicService.save(topic);
			
			
				
				JSONObject returnjson=new JSONObject();
				flag=1;
				returnjson.put("flag",flag);
				 out.println(returnjson.toString());
					out.flush();
					out.close();
		    
		  } catch (ParseException e) {
		    // crash and burn
		    throw new IOException("Error parsing JSON request string");
		  
		  }
	
		  JSONObject returnjson=new JSONObject();
			flag=0;
			returnjson.put("flag",flag);
			 out.println(returnjson.toString());
				out.flush();
				out.close();
	}
	

	//send comment
		
		public void sendcomment() throws Exception{
			
			 PrintWriter out = response.getWriter();
				
				StringBuffer jb = new StringBuffer();
				  String line = null;
				  try {
				    BufferedReader reader = ServletActionContext.getRequest().getReader();
				    while ((line = reader.readLine()) != null)
				      jb.append(line);
				  } catch (Exception e) { /*report an error*/ }

				  HttpServletResponse response = ServletActionContext.getResponse();
					response.setContentType("application/json;charset=utf-8");
			
					
					 try {
						    JSONObject jsonObject = JSONObject.fromObject(jb.toString());
						    Topiccomment topiccomment = new Topiccomment();
							if(jsonObject.containsKey("topicId")){
								long originalTopicId =jsonObject.getLong("topicId");
								topiccomment.setOriginalTopicId(originalTopicId);
							}
							if(jsonObject.containsKey("commentAuthorId")){
								Integer commentAuthorId = jsonObject.getInt("commentAuthorId");
								topiccomment.setCommentAuthorId(commentAuthorId);
							}
							if(jsonObject.containsKey("commentText")){
								String  commentText = jsonObject.getString("commentText");
								topiccomment.setCommentText(commentText);	
							}
							if(jsonObject.containsKey("commentPicture")){
								String  commentPicture = jsonObject.getString("commentPicture");
								topiccomment.setCommentPicture(commentPicture);
							}
							if(jsonObject.containsKey("isReplyComment")){
								Integer isReplyComment = jsonObject.getInt("isReplyComment");
								topiccomment.setIsReplyComment(isReplyComment);
								}
							if(jsonObject.containsKey("originalCommentorName")){
								String  originalCommentorName = jsonObject.getString("originalCommentorName");
								topiccomment.setOriginalCommentorName(originalCommentorName);
								}
							if(jsonObject.containsKey("originalCommentId")){
								long  originalCommentId = jsonObject.getLong("originalCommentId");
								topiccomment.setOriginalCommentId(originalCommentId);
								}
							
							Date date=new Date();
							topiccomment.setCommentTime(date);
							
							topicCommentService.save(topiccomment);
							
								JSONObject returnjson=new JSONObject();
								flag=1;
								returnjson.put("flag",flag);
								 out.println(returnjson.toString());
									out.flush();
									out.close();
						    
						  } catch (ParseException e) {
						    // crash and burn
						    throw new IOException("Error parsing JSON request string");
						  
						  }
					
						  JSONObject returnjson=new JSONObject();
							flag=0;
							returnjson.put("flag",flag);
							 out.println(returnjson.toString());
								out.flush();
								out.close();
					
					
			
		}
		
	//upload imagefile
		
		public void uploadfile() throws Exception{
			
			
			 PrintWriter out = response.getWriter();
				
				StringBuffer jb = new StringBuffer();
				  String line = null;
				  try {
				    BufferedReader reader = ServletActionContext.getRequest().getReader();
				    while ((line = reader.readLine()) != null)
				      jb.append(line);
				  } catch (Exception e) { /*report an error*/ }

				  try {
					    JSONObject jsonObject = JSONObject.fromObject(jb.toString());
					    
					    String uploadPath;
						String fileName = jsonObject.getString("fileName");
						//ByteArrayInputStream is = new ByteArrayInputStream(jsonObject.get("fileData").toString().getBytes());
						BASE64Decoder decoder = new BASE64Decoder();
						String imageStr = jsonObject.get("fileData").toString();
						byte[] isbyte = decoder.decodeBuffer(imageStr);
						String path = ServletActionContext.getRequest().getContextPath();
						String basePath = ServletActionContext.getRequest().getScheme()+"://"+ServletActionContext.getRequest().getServerName()+":"+ServletActionContext.getRequest().getServerPort()+path+"/";
						
						uploadPath = ServletActionContext.getServletContext().getRealPath("/clubUpload_img");
						File dirFile = new File(uploadPath);
						// 判断当前文件夹（路径）是否存在，如果不存在则创建
				        if (!dirFile.exists()) {
				        	//dirFile.mkdirs();
				        	dirFile.mkdir();
				        }
				        //为文件重命名
						String realfileName = java.util.UUID.randomUUID().toString();
						realfileName += ".jpg";  
						File toFile = new File(uploadPath, realfileName);
						
						//logger.info("图片存入本地的路径="+uploadPath+"\\"+fileName);
						BufferedOutputStream  stream = null;
						try{
							FileOutputStream os = new FileOutputStream(toFile);
							stream = new BufferedOutputStream(os);
							stream.write(isbyte);
						}
						finally{
							stream.close();
						}
	
						String srcImagePath=uploadPath+"/"+realfileName;
						String toImagePath=uploadPath+"/"+realfileName;

						OperateImage operateimage=new OperateImage();
						operateimage.reduceImageEqualProportion(srcImagePath, toImagePath, 1);
						
						//logger.info("图片存数据库的路径="+"images/clubUpload_img/"+topic.getTopicAuthorId()+fileName);
						//topic.setTopicImageUrl(basePath+"images/clubUpload_img/"+topic.getTopicAuthorId()+"/topicImg/"+fileName);
					    
						JSONObject returnjson=new JSONObject();
						flag=1;
						String imageurl = basePath+"clubUpload_img/"+realfileName;
						returnjson.put("flag",flag);
						returnjson.put("imageurl", imageurl);
						 out.println(returnjson.toString());
							out.flush();
							out.close();
				  }
				  catch (ParseException e) {
					    // crash and burn
					    throw new IOException("Error parsing JSON request string");
					  
					  
					  }
			
				
				
		}
	
		//filter category
		public void selectclassify() throws Exception{
			String classifyId= ServletActionContext.getRequest().getParameter("classifyId");
			String clubId= ServletActionContext.getRequest().getParameter("clubId");
			String pageNum =  ServletActionContext.getRequest().getParameter("pageNum");
			String pageSize =  ServletActionContext.getRequest().getParameter("pageSize");
		    HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("application/json;charset=utf-8");
			PrintWriter out = response.getWriter();
			
			JSONObject returnjson=new JSONObject();
			JSONArray jsonarray=new JSONArray();
			int intclubid=Integer.parseInt(clubId);
			int intclassifyId = Integer.parseInt(classifyId);
			int intpageNum = Integer.parseInt(pageNum);
			int intpageSize = Integer.parseInt(pageSize);
			if(clubId!=null&&!clubId.equals("")&&classifyId != null){		
				topiclist=topicService.getTopicListByClubIdAndClassifyId(intclubid, intclassifyId, intpageNum, intpageSize);
				System.out.println(topiclist);
	            if(topiclist!=null){
	            	
	            	List<Map<String, Object>> topics=new ArrayList<Map<String, Object>>();
	            	
	            	for(Topic temTopic:topiclist){
	            		int userId = temTopic.getTopicAuthorId();
	            		Users user = usersservice.findByUserID(userId);
	            		
	            		Map<String, Object> params = new HashMap<String, Object>();
	    				params.put("topic", temTopic);
	    				params.put("userNickName",user.getNickName() );
	    				params.put("userName",user.getUserName() );
	    				topics.add(params);
					}
	            	JSONArray jsonbean=JSONArray.fromObject(topics);
					flag=1;
					returnjson.put("flag",flag);
			
					returnjson.put("info", jsonbean);					
				}
				else{
					returnjson.put("flag", flag);
				}
			}
			else{
				returnjson.put("flag", flag);
			}
			out.println(returnjson.toString());
			out.flush();
			out.close();
		}
		
		
		//hospital list
		public void getHospitallist() throws Exception{
			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("application/json;charset=utf-8");
			 PrintWriter out = response.getWriter();
			 
			JSONObject returnjson=new JSONObject();
			
			List<Club> clubcategories = clubService.findHosClub();
			System.out.println(clubcategories);
	        if(clubcategories!=null){
	        	
	        	JSONArray jsonbean=JSONArray.fromObject(clubcategories);
				flag=1;
				returnjson.put("flag",flag);
				returnjson.put("info", jsonbean);				
			}
			else{
				returnjson.put("flag", flag);
			}
	       
	        out.println(returnjson.toString());
			out.flush();
			out.close();
			
		}
		
		//doctor list
		public void getDoctorlist() throws Exception{
			String clubid= ServletActionContext.getRequest().getParameter("clubid");
		
		    HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("application/json;charset=utf-8");
			PrintWriter out = response.getWriter();
			
			JSONObject returnjson=new JSONObject();
			JSONArray jsonarray=new JSONArray();
			int intclubid=Integer.parseInt(clubid);
			
			if(clubid!=null&&!clubid.equals("")){		
				List<DoctorInfo> doctorlist = new ArrayList<DoctorInfo>();
				doctorlist = doctorInfoService.findByHosId(intclubid, 1, 100);
				System.out.println(doctorlist);
	            if(doctorlist!=null){
	            	
	            	JSONArray jsonbean=JSONArray.fromObject(doctorlist);
					flag=1;
					returnjson.put("flag",flag);
			
					returnjson.put("info", jsonbean);				
				}
				else{
					returnjson.put("flag", flag);
				}
			}
			else{
				returnjson.put("flag", flag);
			}
			out.println(returnjson.toString());
			out.flush();
			out.close();
			
		}
		
		//doctor tocpic list
		public void getDoctorTopiclist() throws Exception{
			String topicClassifyId= ServletActionContext.getRequest().getParameter("topicClassifyId");
			String doctorId= ServletActionContext.getRequest().getParameter("doctorId");
			String clubId= ServletActionContext.getRequest().getParameter("clubId");
			String pageNum =  ServletActionContext.getRequest().getParameter("pageNum");
			String pageSize =  ServletActionContext.getRequest().getParameter("pageSize");
		    HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("application/json;charset=utf-8");
			PrintWriter out = response.getWriter();
			
			JSONObject returnjson=new JSONObject();
			JSONArray jsonarray=new JSONArray();
			
			int inttopicClassifyId = -1;
			if(topicClassifyId != null){
				inttopicClassifyId=Integer.parseInt(topicClassifyId);
			}
			int intclubid=Integer.parseInt(clubId);
			int intdoctorId = Integer.parseInt(doctorId);
			int intpageNum = Integer.parseInt(pageNum);
			int intpageSize = Integer.parseInt(pageSize);
			if(clubId!=null&&!clubId.equals("")){		
				topiclist=topicService.getDocTopicList(intclubid, intdoctorId, inttopicClassifyId, 0, intpageNum, intpageSize);
				System.out.println(topiclist);
	            if(topiclist!=null){
	            	
	            	List<Map<String, Object>> topics=new ArrayList<Map<String, Object>>();
	            	
	            	for(Topic temTopic:topiclist){
	            		int userId = temTopic.getTopicAuthorId();
	            		Users user = usersservice.findByUserID(userId);
	            		
	            		Map<String, Object> params = new HashMap<String, Object>();
	    				params.put("topic", temTopic);
	    				params.put("userNickName",user.getNickName() );
	    				params.put("userName",user.getUserName() );
	    				topics.add(params);
					}
	            	JSONArray jsonbean=JSONArray.fromObject(topics);
					flag=1;
					returnjson.put("flag",flag);
			
					returnjson.put("info", jsonbean);					
				}
				else{
					returnjson.put("flag", flag);
				}
			}
			else{
				returnjson.put("flag", flag);
			}
			out.println(returnjson.toString());
			out.flush();
			out.close();
			
		}
		
		
	/**
	 * @param args
	 */
	public Club getClub() {
		return club;
	}


	public void setClub(Club club) {
		this.club = club;
	}


	public Topic getTopic() {
		return topic;
	}

	public void setTopic(Topic topic) {
		this.topic = topic;
	}

	public Users getCommentuser() {
		return commentuser;
	}

	public void setCommentuser(Users commentuser) {
		this.commentuser = commentuser;
	}

	public Userdata getUserdata() {
		return userdata;
	}

	public void setUserdata(Userdata userdata) {
		this.userdata = userdata;
	}
	
	public Userdata getCommentuserdata() {
		return commentuserdata;
	}


	public void setCommentuserdata(Userdata commentuserdata) {
		this.commentuserdata = commentuserdata;
	}


	public List<Topicclassify> getTopicClassifyList() {
		return topicClassifyList;
	}

	public void setTopicClassifyList(List<Topicclassify> topicClassifyList) {
		this.topicClassifyList = topicClassifyList;
	}
	
	public List<Topic> getTopiclist() {
		return topiclist;
	}

	public void setTopiclist(List<Topic> topiclist) {
		this.topiclist = topiclist;
	}

	public List<Topiccomment> getTopiccommentlist() {
		return topiccommentlist;
	}

	public void setTopiccommentlist(List<Topiccomment> topiccommentlist) {
		this.topiccommentlist = topiccommentlist;
	}


	public List<Users> getCommentuserlist() {
		return commentuserlist;
	}


	public void setCommentuserlist(List<Users> commentuserlist) {
		this.commentuserlist = commentuserlist;
	}


	public List<Userdata> getCommentuserdatalist() {
		return commentuserdatalist;
	}


	public void setCommentuserdatalist(List<Userdata> commentuserdatalist) {
		this.commentuserdatalist = commentuserdatalist;
	}

	@Override
	public void setServletResponse(HttpServletResponse response) {
		// TODO Auto-generated method stub
		this.response = response;
		
	}


}
